package fr.ants.view.renderer.pixel;

import java.awt.Color;
import java.awt.Graphics2D;

import fr.ants.model.Node;
import fr.ants.view.panel.Canvas;
import fr.ants.view.renderer.NodeRenderer;

/**
 * <p>Renders a node (ground) with pixels.</p> 
 *
 * @author Vianney DUPOY DE GUITARD
 */
public class NodeGrayPixelRenderer implements NodeRenderer {

	/** {@inheritDoc} */
	public void draw(int x, int y, Graphics2D g, Node node) {
		int color = (int) (255 -(255 * (node.getDifficulty() / 100D)));
		g.setColor(new Color(color, color, color));// différence de gris
		
		
		g.fillRect(x * Canvas.NODE_SIZE, y * Canvas.NODE_SIZE, Canvas.NODE_SIZE, Canvas.NODE_SIZE);
		float pheromoneLevel = node.getPheromoneLevel();
		if (pheromoneLevel > 0) {
			int alpha = pheromoneLevel > 255 ? 255 : (int) pheromoneLevel;
			g.setColor(new Color(250, 170, 250, alpha));
			g.fillRect(x * Canvas.NODE_SIZE, y * Canvas.NODE_SIZE, Canvas.NODE_SIZE, Canvas.NODE_SIZE);
		}
		if (!node.isWalkable()) {
			g.setColor(new Color(0, 0, 0));
			
			g.fillRect(x * Canvas.NODE_SIZE, y * Canvas.NODE_SIZE, Canvas.NODE_SIZE, Canvas.NODE_SIZE);
		}
	}
}